import { Module, MiddlewareConsumer } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { WorkflowTemplateController } from './workflow-template.controller';
import { WorkflowTemplateService } from './workflow-template.service';
import { WorkflowTemplate, WorkflowTemplateSchema } from './schemas/workflow-template.schema';
import { FileUploadService } from '../common/services/file-upload.service';
import { FileUploadMiddleware } from '../common/middleware/file-upload.middleware';

@Module({
    imports: [
        MongooseModule.forFeature([
            { name: WorkflowTemplate.name, schema: WorkflowTemplateSchema }
        ])
    ],
    controllers: [WorkflowTemplateController],
    providers: [WorkflowTemplateService, FileUploadService],
    exports: [WorkflowTemplateService]
})
export class WorkflowTemplateModule {
    configure(consumer: MiddlewareConsumer) {
        consumer
            .apply(FileUploadMiddleware)
            .forRoutes(
                'templates/upload/thumbnail',
                'templates/upload/previews'
            );
    }
}